
<!DOCTYPE html>
<html>
<head>
    <title>Testjs</title>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
</head>

<body>
    <div id="title"><h3>TestJs | 飞良不是个好女人！</h3></div>

    <h1>schema测试</h1>
    <ul>
        <li><a href="joggers://gear">返回商城首页</a></li>
        <li><a href="joggers://gearStore">装备库</a></li>
        <li><a href="joggers://orderPay/201702161509595552">支付</a></li>
    </ul>
</body>

<script type="text/javascript">
    var apis = [
        {
            "title": "设置标题",
            "api": "set_title",
            "param": {
                "title": "啦啦啦"
            },
            "callback": "",
        },
        {
            "title": "开启返回按钮-显示",
            "api": "back_button",
            "param": {
                "status": true
            },
            "callback": "",
        },
        {
            "title": "开启返回按钮-隐藏",
            "api": "back_button",
            "param": {
                "status": false
            },
            "callback": "",
        },
        {
            "title": "设置返回按钮链接",
            "api": "back_url",
            "param": {
                "url": "http://www.hupu.com"
            },
            "callback": "",
        },
        {
            "title": "开启关闭按钮-显示",
            "api": "close_button",
            "param": {
                "status": true
            },
            "callback": "",
        },
        {
            "title": "开启关闭按钮-隐藏",
            "api": "close_button",
            "param": {
                "status": false
            },
            "callback": "",
        },
        {
            "title": "开启分享按钮-显示",
            "api": "share_button",
            "param": {
                "status": true
            },
            "callback": "",
        },
        {
            "title": "开启分享按钮-隐藏",
            "api": "share_button",
            "param": {
                "status": false
            },
            "callback": "",
        },
        {
            "title": "设置分享内容",
            "api": "set_share_info",
            "param": {
                "title": "分享标题1",
                "description": "分享描述1",
                "img_url": "http://wdc.image.alimmdn.com/2.jpg?t=1445479753931",
                "link_url": "http://www.hupu.com"
            },
            "callback": "",
        },
        {
            "title": "直接分享到指定渠道",
            "api": "share",
            "param": {
                "channel": "weixin_side"
            },
            "callback": "",
        },
        {
            "title": "选择文件打开目录",
            "api": "upload_file",
            "param": {
                "path": "album"
            },
            "callback": "album_callback",
        },
        {
            "title": "打开『Scheme』对应功能 - 登录",
            "api": "scheme",
            "param": {
                "scheme": "joggers://login"
            },
            "callback": "",
        },
        {
            "title": "截取内置浏览器内区域内容为图片-带callback",
            "api": "screenshot",
            "param": "",
            "callback": "alert_title",
        },
        {
            "title": "复制链接按钮-隐藏",
            "api": "copy_current_url",
            "param": {
                "status": false,
            },
            "callback": "",
        },
        {
            "title": "复制链接按钮-显示",
            "api": "copy_current_url",
            "param": {
                "status": true,
            },
            "callback": "",
        },
        {
            "title": "获取GPS坐标",
            "api": "get_location",
            "param": "",
            "callback": "get_location_callback",
        },
        {
            "title": "弹窗无按钮",
            "api": "alert",
            "param": {
                "title": "你已催过货了",
            },
            "callback": "",
        },
        {
            "title": "弹窗一个按钮",
            "api": "alert",
            "param": {
                "title": "扑妞正在加紧安排发货",
                "button": "知道了",
            },
            "callback": "alert_title",
        },
        {
            "title": "弹窗两个按钮",
            "api": "confirm",
            "param": {
                "title": "确认收货吗？"
            },
            "callback": "alert_title",
        },
        {
            "title": "图片浏览",
            "api": "lightbox",
            "param": {
                "current": "http://www.hupucdn.com/uploads/hupu/focus/focus-large-2106_2017-02-13.jpg",
                "url":[
                    "http://www.hupucdn.com/uploads/hupu/focus/focus-large-4310_2017-02-13.jpg",
                    "http://www.hupucdn.com/uploads/hupu/focus/focus-large-5067_2017-02-13.jpg",
                    "http://www.hupucdn.com/uploads/hupu/focus/focus-large-2106_2017-02-13.jpg",
                ]
            },
            "callback": "",
        },
        {
            "title": "打开普通导航栏浏览器",
            "api": "wv_new",
            "param": {
                "title": "页面title",
                "nav":[
                    {
                        "name": "刷新",
                        "scheme": "joggers://wv_refresh",
                        "icon": "http://jog-test.mobileapi.hupu.com/static/images/icon/quan_min.png",
                        "position": 0
                    },
                    {
                        "name": "复制",
                        "scheme": "joggers://wv_copy_url",
                        "icon": "http://jog-test.mobileapi.hupu.com/static/images/icon/cp.png",
                        "position": 1
                    },
                    {
                        "name": "分享",
                        "scheme": "joggers://wv_share",
                        "icon": "http://jog-test.mobileapi.hupu.com/static/images/icon/up.png",
                        "position": 1
                    }
                ]
            },
            "callback": "",
        },
        {
            "title": "打开搜索导航栏浏览器",
            "api": "wv_new_gearsearch",
            "param": {
                "title": "搜索框默认值",
                "nav":[
                    {
                        "name": "刷新",
                        "schema": "schema://wv_refresh",
                        "icon": "http://jog-test.mobileapi.hupu.com/static/images/icon/quan_min.png",
                        "position": 0
                    },
                    {
                        "name": "复制",
                        "schema": "schema://wv_copy_url",
                        "icon": "http://jog-test.mobileapi.hupu.com/static/images/icon/cp.png",
                        "position": 1
                    },
                    {
                        "name": "分享",
                        "schema": "schema://wv_share",
                        "icon": "http://jog-test.mobileapi.hupu.com/static/images/icon/up.png",
                        "position": 1
                    }
                ]
            },
            "callback": "",
        }
    ];

    function alert_title() {
        jw.api('alert', JSON.stringify({
            "title": "飞良不是个好女人!",
        }),'');
    }

    function album_callback(img_url) {
        alert(img_url);
    }

    function get_location_callback(location) {
        alert(JSON.stringify(location));
    }

    $(function(){
        var sup = typeof jw === "object";

        if(!sup) {
            $("#title").append("<div><h5>不支持jw.api | type:" + (typeof jw) + "</h5></div>");
        }

        $(apis).each(function(i, api){
            var oid = api.api + i;
            $("#title").append("<div><button id=\"" + oid + "\">" + api.title + "</button></div>");
            $("#" + oid).click(function(){
                if(sup) {
                    jw.api(api.api, JSON.stringify(api.param), api.callback);
                } else {
                    console.log(api.api, JSON.stringify(api.param), api.callback);
                }
            });
        });        
    });



</script>

</html>
